﻿@model  CartListModel
@{
    ViewBag.Title = "List";
    Layout = "~/Views/Shared/_Layout.cshtml";
}


<section class="layui-larry-box">
    <div class="larry-personal">
        <div class="layui-tab">
            <blockquote class="layui-elem-quote cart_search">
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-normal cartAdd_btn">添加购物车</a>
                </div>
                <div class="layui-inline">
                    <a class="layui-btn layui-btn-danger batchDel">批量删除</a>
                </div>
                <div class="layui-inline">
                    <div class="layui-form-mid layui-word-aux">本页面刷新后除新添加的文章外所有操作无效，关闭页面所有数据重置</div>
                </div>
                <div class="layui-inline">
                    <span class="layui-form-mid">共有<span style="font-weight: bold"> @Model.CartRecords.Count()</span>条数据</span>
                </div>
            </blockquote>

            <div class="row">
                <div class="col-lg-6 col-lg-offset-2">
                    <input class="" type="text" name="name" value="" />
                </div>
            </div>


            <!-- 操作日志 -->
            <div class="layui-form cart_list">
                <table class="layui-table">
                    <colgroup>
                        <col width="10%">
                        <col>
                        <col>
                        <col>
                        <col>
                    </colgroup>
                    <thead>
                        <tr>
                            <th>
                                <input name="" lay-skin="primary" lay-filter="allChoose" id="allChoose" type="checkbox">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary">
                                    <i class="layui-icon"></i>
                                </div>
                            </th>
                            <th>用户名</th>
                            <th>商品名</th>
                            <th>数量</th>
                            <th>是否已支付</th>
                            <th>添加该商品到购物车的时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody class="cart_content">
                        @foreach (var cart in Model.CartRecords)
                        {
                            <tr>
                                <td>
                                    <input name="checked" lay-skin="primary" lay-filter="choose" type="checkbox">
                                    <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon"></i></div>
                                </td>
                                <td>@cart.UserName</td>
                                <td>@cart.GoodName</td>
                                <td>@cart.Count</td>
                                <td>
                                    @if (cart.IsBuy)
                                    {
                                        @("已支付")
                                    }
                                    else
                                    {
                                        @("未支付")
                                    }
                                </td>
                                <td>@cart.CreateDateTime</td>
                                <td>
                                    <a class="layui-btn layui-btn-mini cart_edit"><i class="iconfont icon-edit" data-id="@cart.Id"></i> 编辑</a>
                                    <a class="layui-btn layui-btn-danger layui-btn-mini cart_del" data-id="1">
                                        <i class="layui-icon"></i> 删除
                                    </a>
                                </td>
                            </tr>
                        }

                    </tbody>
                </table>
                <div class="larry-table-page clearfix">
                    <div id="page" class="page">@Html.Raw(Model.Page)</div>
                </div>
            </div>

        </div>
    </div>

</section>

@section FooterScript{
    <script type="text/javascript">

        var appConfig = {
            name: "cart",    //需要和页面名称对应
            title: "购物车",    //显示的名称
            addUrl: "/Cart/AddNew",   //添加弹框的路径
            editUrl: "permissionEdit.html",      //修改弹框的路径
            $: "",
            layer: "",
            area: ['100%', '1000px'],

            //批量删除Ajax
            batchDel: function (data) {     //Array data 得到的是 需要删除的id
                data.each(function (index, value) {
                    console.log(value);

                    //todo:在此处添加批量删除记录的ajax

                });

            },
            del: function (data) {

                console.log(data);
                $ = appConfig.$;

                $.ajax({
                    url: "/Cart/Delete",
                    type: "post",
                    dataType: "json",
                    data: { id: data },
                    success: function (res) {
                        if (res.status == "ok") {
                            appConfig.layer.msg("删除成功", { time: 1000, icon: 1 });
                        } else if (res.status == "redirect") {
                            location.href = res.msg;
                        } else {
                            appConfig.layer.msg("错误", { time: 1000, icon: 2 });
                        }
                    }
                })
            }
        };

        layui.use(['jquery', 'layer', 'element', 'laypage'], function () {
            window.jQuery = window.$ = layui.jquery;
            window.layer = layui.layer;
            var element = layui.element(),
                laypage = layui.laypage;



        });
    </script>
}

